class Address < ActiveRecord::Base
  set_table_name :user_addresses

  belongs_to :user_info, :touch => true

  validates :street, :length => {:maximum => 40}, :presence => true
  validates :city, :length => {:maximum => 30}, :presence => true
  validates :zip, :length => {:maximum => 6}, :format => {:with => Format::ZIP_REGEX}, :presence => true

  def same_as?(other_address)
    attributes.except("id") == other_address.attributes.except("id")
  end
  alias same_as same_as?

  def clone_address
    Address.new(self.attributes.except("id"))
  end
end
